set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
# 由cflags指定std=c99， 如果由这里的CMAKE_C_STANDARD指定，会引入gnu99， 这会放到flags最后，
# 从而导致系统不会使用_ISOC99_SOURCE的宏, 从而会导致系统采用的是GNU的source。
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_BUILD_TYPE "Debug")


set(FNO_BUILTIN_FLAGS "-fno-builtin-printf -fno-builtin-time -fno-builtin-gmtime -fno-builtin-gettimeofday -fno-builtin-mktime -fno-builtin-puts")
set(ROOT_DIR "${CMAKE_SOURCE_DIR}/../../../../../cross_tool/gcc-arm-none-eabi")
get_filename_component(ROOT_DIR_FULL "${ROOT_DIR}" ABSOLUTE)                     

set(CMAKE_FIND_ROOT_PATH "${ROOT_DIR_FULL}/arm-none-eabi" "${ROOT_DIR_FULL}/lib/gcc/arm-none-eabi/7.3.1")
set(CMAKE_SYSROOT "${ROOT_DIR_FULL}/arm-none-eabi")
set(CMAKE_AR "${ROOT_DIR_FULL}/bin/arm-none-eabi-ar.exe")
set(CMAKE_ASM_COMPILER "${ROOT_DIR_FULL}/bin/arm-none-eabi-as.exe")
set(CMAKE_C_COMPILER "${ROOT_DIR_FULL}/bin/arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "${ROOT_DIR_FULL}/bin/arm-none-eabi-g++.exe")
set(CMAKE_STATIC_LIBRARY_SUFFIX_C .lib)
set(STDLINK_LIB "${ROOT_DIR_FULL}/arm-none-eabi/lib/thumb/v7-ar/libm.a ${ROOT_DIR_FULL}/arm-none-eabi/lib/thumb/v7-ar/libc.a ${ROOT_DIR_FULL}/arm-none-eabi/lib/thumb/v7-ar/libnosys.a ${ROOT_DIR_FULL}/lib/gcc/arm-none-eabi/7.3.1/thumb/v7-ar/libgcc.a")

set(FNO_BUILTIN_FLAGS "-fno-builtin-printf -fno-builtin-time -fno-builtin-gmtime -fno-builtin-gettimeofday")
set(CMAKE_C_FLAGS_INIT "-c -MMD -mlong-calls -march=armv7-r  -mcpu=cortex-r4 -mlittle-endian -mthumb -mthumb-interwork -mfloat-abi=soft -Wall -ffunction-sections -fdata-sections ${FNO_BUILTIN_FLAGS} -Wstrict-prototypes -std=c99 -g -Os")
set(CMAKE_CXX_FLAGS_INIT "-c -MMD -mlong-calls -march=armv7-r  -mcpu=cortex-r4  -mlittle-endian -mthumb -mthumb-interwork -mfloat-abi=soft -Wall -ffunction-sections -fdata-sections ${FNO_BUILTIN_FLAGS} -Wstrict-prototypes -std=c99 -g -Os")
set(CMAKE_ASM_FLAGS_INIT "-c -mlong-calls -march=armv7-r  -mcpu=cortex-r4 -mlittle-endian -mthumb -mthumb-interwork -mfloat-abi=soft -Wall -Wstrict-prototypes -Os")

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
